﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Transfer.Domain;
using S.Transfer.Domain.Model;
using S.Transfer.Read.API.Application.Command.UserCommand;
using S.Transfer.Read.API.Extensions.Dto;

namespace S.Transfer.Read.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SheepFromController : BaseController
    {
        private readonly IMediator mediator;
        public SheepFromController(IMediator _mediator,MySqlDbContext db):base(db)
        {
            mediator = _mediator;
        }
        [Authorize]
        [HttpGet("Name")]
        public IActionResult Name ()
        {
            return Ok(UserStrategyDto.UserTrueName);
        }
        /// <summary>
        /// 转舍显示
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFromDto")]
        public async Task<Pager<SheepShowDto>> GetSheepFromDto(DateTime? SurrenderDate,string? EarTag,int? RoundType,int? TurnOutBuild, int? TurnOutHuts,int? ShiftToBuild,int? ShiftToHuts,int PageIndex,int PageSize)
        {
            return await mediator.Send(new TransferShowlCommond() { SurrenderDate= SurrenderDate,EarTag=EarTag,RoundType=RoundType, TurnOutBuild = TurnOutBuild, TurnOutHuts = TurnOutHuts, ShiftToBuild = ShiftToBuild, ShiftToHuts = ShiftToHuts,PageIndex=PageIndex,PageSize=PageSize });
        }
        /// <summary>
        /// 转舍显示部分字段
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFrom")]
        public async Task<List<SheepFromDto>> GetSheepFrom(string EarTag)
        {
            return await mediator.Send(new TransferCommond() { EarTag = EarTag });
        }
        /// <summary>
        /// 根据耳号显示最新消息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFromByDate")]
        public async Task<SheepRescission> GetSheepFromByDate(string EarTag)
        {
            return await mediator.Send(new TransFerByDateCommond() { EarTag = EarTag });
        }
        /// <summary>
        /// 根据耳号显示最新消息
        /// </summary>
        /// <returns></returns>
        [HttpGet("GetSheepFromById")]
        public async Task<SheepShowDto> GetSheepFromById(string EarTag)
        {
            return await mediator.Send(new TransFerByIdCommand() { EarTag = EarTag });
        }
        /// <summary>
        /// 返填单纯转舍且是最新数据
        /// </summary>
        /// <param name="EarTag"></param>
        /// <param name="SurrenderDate"></param>
        /// <returns></returns>
        [HttpGet("GetSheepFromByIdEartag")]
        public async Task<IActionResult> GetSheepFromByIdEartag(string EarTag, DateTime? SurrenderDate)
        {
            return Ok(await mediator.Send(new TransFerByIdEarTag() { EarTag = EarTag, SurrenderDate = SurrenderDate }));
        }
    }
}
